This CDEF started out as a "quick hack" project. I was experimenting with a couple of Photoshop filter ideas, and needed a basic slider control for the settings dialog. A search on AOL turned up pretty much empty (there are a couple of slider CDEFs available, but none seemed very flexible), so I resolved to write my own. RadSlider was the result, and I think you'll find it will do just about anything a slider needs to do.
••Basic Operation
RadSliders are created and operated just like any other kind of control. The CDEF determines, based on the larger dimension of the control rectangle, whether the slider should be drawn horizontally or vertically. Click and drag in the handle or slider bar to adjust the control's value; the handle will "jump" between valid positions (integer values of the control value) to facilitate precise positioning.
The RadSlider CDEF uses the controlData field to store a region that covers the control. This region is maintained through user drags and calcCtlRgn messages. The RefCon field is left free for your own use.
Horizontal sliders put contrlMin% at the left side and contrlMax% at the right side of the slider bar; vertical sliders put contrlMin% at the bottom and contrlMax% at the top. If the control rectangle is larger than RadSlider needs, the control will be centered within its rectangle.
••Colors
RadSlider is pretty smart about colors. If the control has a color table, it will use its _cFrameColor, _cBodyColor, _cTextColor, and _cThumbColor entries for the slider bar outline, the slider bar fill, the text, and thumb fill, respectively. If the body color is white (the default), the control instead uses a 60%/25% gray pattern for the slider bar fill.
If a _cBodyColor is specified, it will be used for the slider bar fill foreground color, and a 50% brighter version of the color will be used for the background color. This creates a softer fill which is much nicer on the eyes than simply using the body color as the foreground color and white as the background.
•• Goodies
If you use a variation code of +1, the CDEF will use the 'tinge color' for the slider bar fill if available (the color found on the scroll bar arrows). The two colors, _cTingeLight and _cTingeDark, will be used in the standard 50% gray fill.
Adding a variation code of +2 causes RadSlider to draw tick marks at each valid position along either the top or left side of the slider, depending on the slider's orientation. These ticks will be drawn in the slider's frame color. Note that there is no "step" value; for aesthetic reasons, I don't recommend using tick marks when you have a large range of selectable values in a small space (it looks pretty ugly).
Control titles are supported (as of RadSlider 1.5). The default is to use Geneva 9 text, but if you add _useWFont (+8) to the varcode, the current window font will be used instead. The title is normally drawn left-justified above the slider (in both horizontal and vertical mode), but you can force the title to move below the slider by preceding the text with a return character (ASCII=13). The return must be the first character in the string.
Another new feature - since the Control Manager doesn't allow your application to have control while the slider is being slid, there's no way you can do any kind of user feedback until the mouse is let up. Instead, you can now set varcode +4, and RadSlider will display the control's current value as it is changed. The value will be right justified, across from the control title (above or below the slider bar, to match the title), and in the same text style as the control title.
••Safety Features
RadSlider does not affect the operation of your window in any way I am aware of: the CDEF restores the pen state, foreground & background colors, font/size/style/mode, and clip region when it is done drawing. RadSlider does not have any problems with non-white backgrounds, either.
••Other Stuff
Version 1.0.1 fixes a glitch in the vertical slider drawing code that caused excessive flashing when the slider was dragged.
Version 1.1 is revised internally, and adds the tick mark option.
Version 1.5 adds the control title and current value display options, and shortens the tick marks slightly (the original ticks were a bit too long for my liking).
RadSlider CDEF is freeware. I retain the copyright, but place no restrictions on distribution or use. I'd *like* to hear from you if you use RadSlider in a project, and sticking my name in an obscure corner of the credits would be even nicer, but it's completely up to you.
I do have one request - if you pass on the RadSlider CDEF, please leave the demo program and this read me file intact and together.
As always, I'd be glad to hear any suggestions for new features!
Jonathan E. Durkee
Red Planet Software
9205 Starina Way
Sacramento, CA 95826
(916) 369-0718 (phone & autoswitched fax, has answering machine)
AOL/eWorld: MarsSaxMan
Those addresses can be reached through the Internet: